<?php

namespace interface\v1;

/*
*消息接口类
*/

class messageAppClass extends index
{
	private const title = '消息接口类';
	
	/*待办事项列表*/
	public function list()
	{
		//数据查询
		$where = " stid = '" . $this->control['stid'] . "' ";
		$page  = $this->page(array("table" => "message", 'num' => 20, "where" => $where, "order" => "FIELD(see,'否','是'),time desc"));
		//数据分析
		$data['result'] = [];
		foreach ($page['array'] as $array) {
			if (empty($array['targetCla']) && empty($array['targetFun'])) {
				$audit           = query('audit', "id = '$array[typeId]'");
				$array['typeId'] = $audit['targetId'];
			}
			
			$data['result'][] = array(
				"id"     => $array['id'],//待办事项ID
				"type"   => $array['type'],//类型
				"typeId" => $array['typeId'],//对象表ID
				"text"   => $array['text'],//待办事项说明
				"see"    => $array['see'],
				'url'    => oaIndexAppClass::navigateTo($array['type'], $array['typeId']),
				"time"   => $array['time'],//创建时间
			);
		}
		//返回
		$data['page'] = $page['para'];
		//返回
		$this->code         = 1;
		$this->resp['data'] = $data;
	}
	
	/**
	 * 消息已读
	 */
	public function readed()
	{
		$id         = $this->post('id');//消息ID
		$this->code = 1;
		update(array('table' => 'message', "field" => ['see' => '是', 'seeTime' => $this->time], 'where' => "id = '$id' and see = '否' and stid = '" . self::$stid . "'"));
	}
}
